const HtmlWebpackPlugin = require("html-webpack-plugin")
const CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports={
    entry:{
        damu:"./src/js/index.js"
    },
    output:{
        filename:"[name].min.js",
        path:`${__dirname}/dist`
    },
    module:{
        rules:[
            {
                test:/\.js$/,
                use:"babel-loader",
                exclude:"/node_modules/"
            },
            {
                test:/\.css$/,
                use:[
                    {
                        loader:"style-loader"
                    },
                    {
                        loader:"css-loader"
                    }
                ]
            },
            {
                test:/\.less$/,
                use:[
                    "style-loader",
                    "css-loader",
                    "postcss-loader",
                    "less-loader"
                ]
            },
            {
                test:/\.(jpg|png)$/,
                use:{
                    loader:"url-loader",
                    options:{
                        publicPath:"../img/xzf",
                        outputPath:"img/xzf",
                        name:"[name].[hash:1].[ext]",
                        limit:10000
                    }
                }
            },
            {
                test:/\.html$/,
                use:[
                    {
                        loader:'html-loader',
                        options:{
                            //attrs:['img:src']
                            attributes:true
                        }
                    }
                ]
            },
            {
                test:/\.(ttf|eot|svg|woff|woff2)$/i,
                use:{
                    loader:"file-loader",
                    options:{
                        publicPath:"../font",
                        outputPath:"font",
                        name:"[name].[hash:1].[ext]"
                    }
                }
            }
        ]
    },
    plugins:[
        new HtmlWebpackPlugin({
            filename:"src/index.html",
            template:"./index.html",
            inject:true //最终webpack打包生成的js文件会被自动注入到filename指定的文件中
        }),
        new CleanWebpackPlugin (['dist'])
    ]
}